package com.aaa.reflection.demo1;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author C-Q
 * @version 1.1.0
 * @Description: 反射
 *
 * 获取Class类对象的三种方式
 * 1，通过类名直接获取
 * 2，通过对象直接获取
 * 3，通过类名的全路径来获取
 *
 * @date 2022/10/25
 */
public class Test {
    public static void main(String[] args) throws Exception {
        //通过全类名获取class反射类对象。
        Class<?> aClass = Class.forName("com.aaa.reflection.demo1.Student");
        //通过类名获取
        Class class01=Student.class;
        //通过对象获取class对象
        Student student = new Student();
        Class class02 =student.getClass();
        System.out.println(class01==aClass);
        System.out.println(class02==aClass);
        //class只会被加载到内存里一次

        Class class03=Father.class;
        System.out.println(class03+"===class03");
    }
}

class Father{
}
@Data
@AllArgsConstructor
 class Student {
    private String name;
    private int age;

    public Student(){
    }
    public void show(){
        System.out.println("show");
    }
}